package com.fenyin.samples.study.jvm.classloader.example1;  

import java.lang.reflect.Method;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fenyin.samples.study.jvm.classloader.FileSystemClassLoader;

/** 
 *@Title:  
 *@Description:  虚拟机判定类是否相同的依据
 *@Author:fengzhichao  
 *@Since:2012-9-21  
 *@Version:1.1.0
 */
public class ClassIndentity {
	private static final Log log = LogFactory.getLog(ClassIndentity.class);
	
	public class Model{
		private Model model;
		
		public void setModel(Object instance){
			model = (Model) instance;
		}
	}
	
	public static void main(String[] args){
		String rootDir = "E:\\workplace\\samples\\samples-study\\target\\classes";
		FileSystemClassLoader classLoader1 = new FileSystemClassLoader(rootDir);
		FileSystemClassLoader classLoader2 = new FileSystemClassLoader(rootDir);
		String className = "com.bj58.samples.study.jvm.classloader.example1.ModelEntity";
		try{
			Class<?> clazz1 = classLoader1.loadClass(className);
			Object obj1 = clazz1.newInstance();
			Class<?> clazz2 = classLoader2.loadClass(className);
			Object obj2 = clazz2.newInstance();
			Method setSampleMethod = clazz1.getMethod("setModel", java.lang.Object.class); 
		    setSampleMethod.invoke(obj1, obj2); 
		}catch(Throwable e){
			log.error("ClassIndentity error",e);
		}
	}
}
